package com.shadow.study.java.base.util.password;

import cn.hutool.crypto.digest.DigestUtil;
import lombok.extern.slf4j.Slf4j;
import org.jasypt.util.text.BasicTextEncryptor;

@Slf4j
public class TestEncryption {

    private static final String PASSWORD = "password";
    private static final String SALT = "salt";

    public static void main(String[] args) {
//        test1();
        jasypt();
    }
    
    /**
     * 计算32位MD5摘要值，并转为16进制字符串
     * */
    private static void test1() {
        log.info(PASSWORD);
        String m = DigestUtil.md5Hex(PASSWORD + SALT);
        log.info(m);
    }

    /**
     * jasypt
     * */
    private static void jasypt() {
        // 该类的选择根据algorithm：PBEWithMD5AndDE选择的算法选择
        BasicTextEncryptor encryptor = new BasicTextEncryptor();
        // aVKM4jX/FYmq6swKUPS7TQ==
        // aVKM4jX/FYmg6sWKUPS7T0==
//        encryptor.setPassword(PASSWORD);
        encryptor.setPassword("dist@2025");
        String encrypt = encryptor.encrypt("Sxzrzy@159260");
        log.info(String.format("=== 加密: %s", encrypt));
        String decrypt = encryptor.decrypt(encrypt);
        log.info(String.format("=== 解密: %s", decrypt));
    }
}
